﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.SqlClient;
using System.IO;


namespace VistaOnlineR1._1.Controllers
{
   
    public  class BackupController : BaseController
    {
        //
        // GET: /Backup/

        public ActionResult CreateBackup()
        {
           

            return View();
        }


        [HttpPost]
        public ActionResult CreateBackup(string path, string nombre)
        {
            bool rta = true;

            //path = "F:\\PROYECTO UNIPAN\\Trabajodecampoydiploma\\VistaOnlineR1.1\\Content\\Respaldo\\";
            path = "C:\\Respaldo\\";

            nombre = "respaldo" + "-" + DateTime.Today.Day + DateTime.Today.Month + DateTime.Today.Year + "-" + string.Format("{0:D2}", DateTime.Now.Hour) + string.Format("{0:D2}", DateTime.Now.Minute) + ".bak";
            rta = Modelo.Sistema.Base.Backup.CreateBackup(path, nombre);
           
            if (rta == true)
                {

                    ViewBag.Estado = "El Backup se creo con exito";
                }

            return View();

        }

        public object RootFolder = "C:\\Respaldo\\";

        public ActionResult RestoredBackup()
        {


            return View(RootFolder);
        }


        [HttpPost]
        public  ActionResult RestoredBackup2( HttpPostedFileBase file)
        {
            bool rta = true;

            //path = "F:\\PROYECTO UNIPAN\\Trabajodecampoydiploma\\VistaOnlineR1.1\\Content\\Respaldo\\";


            string path = "C:\\Respaldo\\" + file.FileName;

            
            rta = Modelo.Sistema.Base.Backup.RestoredBackup(path);

            if (rta == true)
            {

                ViewBag.EstadoRestore = "El Backup se restauro con exito";
            }   

            return View();

        }
    }
}